package com.prs.crm.service.cdxh.impl;

import com.prs.crm.dao.cdxh.MachineClassDao;
import com.prs.crm.domain.cdxh.SerialNumberss;
import com.prs.crm.domain.cdxh.production.MachineClass;
import com.prs.crm.domain.cdxh.production.ProvideRegime;
import com.prs.crm.service.cdxh.MachineClassService;
import com.prs.crm.service.cdxh.ProvideRegimeService;
import com.prs.crm.service.cdxh.SerialNumberssService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-3 上午10:03:08 简单说明
 */

public class MachineClassServiceImpl extends
		BaseServiceImpl<MachineClass, MachineClassDao> implements
		MachineClassService {

	private SerialNumberssService serialNumberssService;
	
	private MachineClassService machineClassService;

	private ProvideRegimeService provideRegimeService;

	/**
	 * 配料
	 */
	@Override
	public void savePL(String productType,MachineClass machineClass, int pl_activeoutput,
			Double pl_activeoutput_jl, Double pl_activeoutput_cf, int pl_scrap,
			Double pl_scrap_jl, Double pl_scrap_cf) {	
		String CodeNumbers="1-PL-1";
		SerialNumberss snObject=this.getSerialNumberssService().getSerialNumberss("生产配料");
		if(snObject==null){
			SerialNumberss  snmm=new SerialNumberss();
			snmm.setStyCategory("生产配料");
			snmm.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().save(snmm);
		}else{
			String codeF=snObject.getStyNumberCode();
			String DF[]=codeF.split("-");
			int startCode=Integer.parseInt(DF[0])+1;
			String lastCode="-"+DF[1]+"-"+DF[2];
			CodeNumbers=startCode+lastCode;
			snObject.setStyNumberCode(CodeNumbers);
			
			this.getSerialNumberssService().setNumCode(snObject);
		}
		
		
		 ProvideRegime  PR=new ProvideRegime();
		 PR.setJudProduct(1);
		 PR.setProductStyle("配料");
		 PR.setMachineNums(machineClass.getMachineNum());
		 PR.setClassNums(machineClass.getClassNum());
		 PR.setRecodeStyle("实际产量");
		 PR.setSetNum(pl_activeoutput);
		 PR.setRewardPrice(pl_activeoutput_jl);
		 PR.setPunishPrice(pl_activeoutput_cf);
		 PR.setInserValue("1");
		 PR.setDiscriminationValue(CodeNumbers);
		 this.getProvideRegimeService().save(PR);		 
		 ProvideRegime  PR1=new ProvideRegime();
		 PR1.setProductStyle("配料");
		 PR1.setMachineNums(machineClass.getMachineNum());
		 PR1.setClassNums(machineClass.getClassNum());
		 PR1.setRecodeStyle("废料");
		 PR1.setJudProduct(1);
		 PR1.setSetNum(pl_scrap);
		 PR1.setRewardPrice(pl_scrap_jl);
		 PR1.setPunishPrice(pl_scrap_cf);
		 PR1.setDiscriminationValue(CodeNumbers);
		 this.getProvideRegimeService().save(PR1);
	}

	/**
	 * 成型
	 */
	@Override
	public void saveCX(String productType,MachineClass machineClassint, int cx_activeoutput,
			Double cx_activeoutput_jl, Double cx_activeoutput_cf, int cx_scrap,
			Double cx_scrap_jl, Double cx_scrap_cf) {
		String CodeNumbers="1-CX-1";
		SerialNumberss snObject=this.getSerialNumberssService().getSerialNumberss("生产成型");
		if(snObject==null){
			SerialNumberss  snmm=new SerialNumberss();
			snmm.setStyCategory("生产成型");
			snmm.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().save(snmm);
		}else{
			String codeF=snObject.getStyNumberCode();
			String DF[]=codeF.split("-");
			int startCode=Integer.parseInt(DF[0])+1;
			String lastCode="-"+DF[1]+"-"+DF[2];
			CodeNumbers=startCode+lastCode;
			snObject.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().setNumCode(snObject);
		}
		 ProvideRegime  PR=new ProvideRegime();
		 PR.setProductStyle("成型");
		 PR.setMachineNums(machineClassint.getMachineNum());
		 PR.setClassNums(machineClassint.getClassNum());
		 PR.setRecodeStyle("实际领料量");
		 PR.setJudProduct(2);
		 PR.setSetNum(cx_activeoutput);
		 PR.setRewardPrice(cx_activeoutput_jl);
		 PR.setPunishPrice(cx_activeoutput_cf);
		 PR.setInserValue("1");
		 PR.setDiscriminationValue(CodeNumbers);
		 this.getProvideRegimeService().save(PR);		 
		 ProvideRegime  PR1=new ProvideRegime();
		 PR1.setProductStyle("成型");
		 PR1.setRecodeStyle("废料");
		 PR1.setJudProduct(2);
		 PR1.setMachineNums(machineClassint.getMachineNum());
		 PR1.setClassNums(machineClassint.getClassNum());
		 PR1.setSetNum(cx_scrap);
		 PR1.setRewardPrice(cx_scrap_jl);
		 PR1.setPunishPrice(cx_scrap_cf);
		 PR1.setDiscriminationValue(CodeNumbers);
		 this.getProvideRegimeService().save(PR1);

	}

	/**
	 * 印刷
	 */
	@Override
	public void saveYS(String productType,MachineClass machineClass, int ys_activeoutput,
			Double ys_activeoutput_jl, Double ys_activeoutput_cf) {
		String CodeNumbers="1-YS-1";
		SerialNumberss snObject=this.getSerialNumberssService().getSerialNumberss("生产印刷");
		if(snObject==null){
			SerialNumberss  snmm=new SerialNumberss();
			snmm.setStyCategory("生产印刷");
			snmm.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().save(snmm);
		}else{
			String codeF=snObject.getStyNumberCode();
			String DF[]=codeF.split("-");
			int startCode=Integer.parseInt(DF[0])+1;
			String lastCode="-"+DF[1]+"-"+DF[2];
			CodeNumbers=startCode+lastCode;
			snObject.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().setNumCode(snObject);
		}
		 ProvideRegime  PR=new ProvideRegime();
		 PR.setProductStyle("印刷");
		 PR.setMachineNums(machineClass.getMachineNum());
		 PR.setClassNums(machineClass.getClassNum());
		 PR.setRecodeStyle("实际生产量");
		 PR.setJudProduct(3);
		 PR.setSetNum(ys_activeoutput);
		 PR.setRewardPrice(ys_activeoutput_jl);
		 PR.setPunishPrice(ys_activeoutput_cf);
		 PR.setInserValue("1");
		 PR.setDiscriminationValue(CodeNumbers);
		 this.getProvideRegimeService().save(PR);		 
		
	}

	@Override
	public MachineClass serchMaxIdObject(String productType) {
		
		return this.getDao().serchMaxIdObject(productType);
	}

	public MachineClassService getMachineClassService() {
		return machineClassService;
	}

	public void setMachineClassService(MachineClassService machineClassService) {
		this.machineClassService = machineClassService;
	}

	public ProvideRegimeService getProvideRegimeService() {
		return provideRegimeService;
	}

	public void setProvideRegimeService(
			ProvideRegimeService provideRegimeService) {
		this.provideRegimeService = provideRegimeService;
	}

	public SerialNumberssService getSerialNumberssService() {
		return serialNumberssService;
	}

	public void setSerialNumberssService(SerialNumberssService serialNumberssService) {
		this.serialNumberssService = serialNumberssService;
	}
	
}
